<template>
	<view>
		<view class="" style="height: 20rpx;"></view>
		<view class="title">
			<view class="tit_l">
				<image :src="infoData.productImage" mode=""></image>
			</view>
			<view class="tit_r">
				<view class="tit">{{infoData.productName}}</view>
				<view class="price"><span>￥</span>{{infoData.productPrice}}</view>
			</view>
		</view>
		<view class="content">
			<view class="item" style="border-bottom: 1px solid #EEEEEE;">
				<view class="">数量</view>
				<input type="number"  v-model="playinfo.productCount" placeholder="请输入数量" />
			</view>
			<view class="item">
				<view class="">车牌号</view>
				<view @click="opens" class="" style="display: flex;align-items: center;color: #9F9F9F;">
					{{playinfo.carNumber ? playinfo.carNumber :'请选择'}}
					<uni-icons type="right" size="22" color="#9F9F9F"></uni-icons>
				</view>
			</view>
		</view>
		<view class="btn">
			<view class="" style="display: flex;align-items: center;">
				<view class="t_l">合计:</view>
				<view class="price"><span>￥</span>{{allprice}}</view>
			</view>
			<view class="btns" @click="handelPlay">
				立即支付
			</view>
		</view>
		<uni-popup ref="popup" type="bottom" :safe-area='false'>
			<view class="tanchu">
				<view class="top">
					<view class="wenzi" style="color: #5070E9;" @click="gocar">
						<span style="">添加车牌</span>
					</view>
					<view class="wenzi">
						<span style="margin-right: -10%;">选择车牌</span>
					</view>
					<uni-icons @click="close()" type="closeempty" size="20"></uni-icons>
				</view>
				<scroll-view scroll-y="true" style="overflow: scroll;height: 420rpx;">
					<view class="hezi" v-for="(item,index) in dizhilist" :key="index" @click="xuanzedizhi(item,index)">
						<view class="left">
							<uni-icons v-if="indexs == index" type="checkbox" color="#5070E9" size="20"></uni-icons>
							<uni-icons v-else type="circle" size="20"></uni-icons>
							<view class="text">
								{{item.carNumber}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		carList,goPlay
	} from '../../common/http.api.js'
	export default {
		data() {
			return {
				dizhilist: [],
				indexs: -1,
				infoData: {},
				playinfo:{
					productId:'',
					productCount:1,
					carNumber:''
				}
			};
		},
		computed:{
			allprice(){
				return this.playinfo.productCount * this.infoData.productPrice
			}
		},
		onLoad(e) {
			this.infoData = JSON.parse(decodeURIComponent(e.info));
			this.playinfo.productId = this.infoData.id
		},
		methods: {
			gocar(){
				uni.navigateTo({
					url:'/pages/my/carList'
				})
				this.$refs.popup.close()
			},
			getcarlist(){
				carList().then(res => {
					if (res.code == 200) {
						this.dizhilist = res.data
					}
				})
			},
			opens() {
				this.getcarlist()
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			},
			xuanzedizhi(item,i) {
				this.indexs = i
				this.playinfo.carNumber = item.carNumber
				this.$refs.popup.close()
			},
			handelPlay(){
				if (uni.getStorageSync('token')) {
					if(this.playinfo.productCount <=0){
						uni.showToast({
							icon:'error',
							title:'请输入正确数量'
						})
					}else if(this.playinfo.carNumber == ''){
						uni.showToast({
							icon:'error',
							title:'请选择车牌号'
						})
					}else{
						goPlay(this.playinfo).then(res=>{
							if(res.code == 200){
								window.location.href =res.data.payUrl
							}
						})
					}
					
				}else{
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
				
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #F6F6F6;
	}

	.title {
		width: 702rpx;
		height: 164rpx;
		margin: 0rpx auto;
		display: flex;
		background-color: #fff;
		padding: 24rpx 20rpx;
		box-sizing: border-box;
		border-radius: 16rpx;

		.tit_l {
			width: 116rpx;
			height: 116rpx;

			image {
				width: 100%;
				height: 116rpx;
				border-radius: 10rpx;
			}
		}

		.tit_r {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 20rpx;

			.tit {
				font-weight: bold;
				font-size: 28rpx;
				color: #282828;
			}

			.price {
				font-weight: bold;
				font-size: 28rpx;
				color: #282828;

				span {
					font-size: 20rpx;
				}
			}

		}
	}

	.content {
		width: 702rpx;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 16rpx;

		.item {
			height: 98rpx;
			display: flex;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;
			justify-content: space-between;

			input {
				width: 160rpx;
				text-align: right;
			}
		}
	}

	.btn {
		position: fixed;
		width: 100%;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		height: 120rpx;
		align-items: center;
		bottom: 0%;
		padding: 40rpx 24rpx;
		box-sizing: border-box;
		border-radius: 20rpx 20rpx 0rpx 0rpx;

		.t_l {
			font-weight: bold;
			font-size: 28rpx;
			color: #282828;
		}

		.price {
			margin-left: 10rpx;
			font-weight: bold;
			font-size: 36rpx;
			color: #FF4800;

			span {
				font-size: 22rpx;
			}
		}

		.btns {
			width: 144rpx;
			height: 56rpx;
			background: linear-gradient(#5070E9 0%, #598DFD 100%);
			color: #fff;
			font-size: 24rpx;
			border-radius: 28rpx;
			text-align: center;
			line-height: 56rpx;
		}
	}



	.tanchu {
		background-color: #FFFFFF;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		height: 440rpx;

		.hezi {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;
			padding-bottom: 20rpx;
			border-bottom: 1rpx solid #EEEEEE;

			.left {
				display: flex;
				align-items: center;
				padding: 0rpx 24rpx;

				.text {
					margin-left: 10rpx;
					font-size: 28rpx;
				}
			}

			.right {
				margin-right: 20rpx;
			}

			image {
				width: 35rpx;
				height: 35rpx;
			}
		}

		.top {
			width: 100%;
			border-bottom: 1px solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding:0rpx 20rpx ;
			box-sizing: border-box;
			.wenzi {
				height: 100rpx;
				text-align: center;
				font-family: Source Han Sans CN;
				font-weight: 400;
				font-size: 30rpx;
				color: #070707;
				line-height: 100rpx;
			}
		}
	}
</style>